﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["MENU_SELECTED"] = 0;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            study.BLL.tb_user userbll = new study.BLL.tb_user();
            study.Model.tb_user usermod = new study.Model.tb_user();
            usermod.username = TextBox1.Text;
           
            if (userbll.GetModel(usermod.username) != null)
            {
                Response.Write("<script LANGUAGE='javascript'>alert('账号已存在！')</script>");
                return;
            }
            if (TextBox2.Text != TextBox3.Text)
            {
                Response.Write("<script LANGUAGE='javascript'>alert('两次输入的密码不一样！')</script>");
                return;
            }
            usermod.pwd = TextBox2.Text;
            usermod.retime = DateTime.Now.ToShortDateString();
            usermod.uimg = "~/images/123.png";
            usermod.recount = usermod.count = 0;
            usermod.admin = false;
            if (userbll.Add(usermod) != 0)
            {
                Response.Write("<script LANGUAGE='javascript'>alert('注册成功！')</script>");
                Response.Redirect("Default.aspx");
            }
            else 
            {
                Response.Write("<script LANGUAGE='javascript'>alert('对不起注册失败！<br /> 请与管理员联系')</script>");
            }
        }
    }
}